// 云函数入口文件
const cloud = require('wx-server-sdk')
const got = require('got'); //引用 gotnpm i got@9.6.0 --save
const Base64 = require('js-base64').Base64;
cloud.init()
 
 // 云函数入口函数
 exports.main = async(event, context) => { 
  var tdata = decodeUTF8(Base64.decode(event.data)).trim();
   let postResponse = await got('url', { 
     method: 'POST', //post请求
     headers: {'Content-Type':'application/json'},
     body: tdata
   }) 
   return postResponse.body //返回数据
 }
 function decodeUTF8(str) {
  return unescape(str.replace(/&#x/g, '%u').replace(/\\u/g, '%u').replace(/;/g, ''));
}
function GetLength(val) {
  var len = 0;
  for (var i = 0; i < val.length; i++) {
    var a = val.charAt(i);
    if (a.match(/[^\x00-\xff]/ig) != null) {
      len += 2;
    }
    else {
      len += 1;
    }
  }
  return len;
}